<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopMpliveTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_mplive_room', ['id' => false, 'primary_key' => 'roomid', 'comment' => '直播间', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('roomid', 'integer', ['limit' => 10, 'null' => false, 'default' => 0, 'comment' => '房间号'])
            ->addColumn('name', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '直播间名称'])
            ->addColumn(Column::tinyInteger('type')->setNull(true)->setDefault(null)->setComment('直播方式'))
            ->addColumn('status', 'integer', ['limit' =>  10, 'null' => true, 'default' => null, 'comment' => '状态'])
            ->addColumn(Column::tinyInteger('is_feeds_public')->setNull(true)->setDefault(null)->setComment('官方推荐'))
            ->addColumn('goods', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '商品'])
            ->addColumn('anchor_name', 'string', ['limit' => 50, 'null' => true, 'default' => null, 'comment' => '主播名称'])
            ->addColumn('share_img', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '分享图'])
            ->addColumn('cover_img', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '封面图'])
            ->addColumn('feeds_img', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '官方封面图'])
            ->addColumn(Column::tinyInteger('close_replay')->setNull(true)->setDefault(null)->setComment('关闭回放'))
            ->addColumn(Column::tinyInteger('close_like')->setNull(true)->setDefault(null)->setComment('关闭点赞'))
            ->addColumn(Column::tinyInteger('close_kf')->setNull(true)->setDefault(null)->setComment('关闭客服'))
            ->addColumn(Column::tinyInteger('close_goods')->setNull(true)->setDefault(null)->setComment('关闭商品橱窗'))
            ->addColumn(Column::tinyInteger('close_comment')->setNull(true)->setDefault(null)->setComment('关闭评论'))
            ->addColumn('creater_openid', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '创建用户'])
            ->addColumn('start_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '开始时间'])
            ->addColumn('end_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '结束时间'])
            ->create();


        $table = $this->table('shop_mplive_goods', ['id' => false, 'primary_key' => 'id', 'comment' => '直播间商品', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('id', 'integer', ['limit' =>  11, 'null' => false, 'default' => 0])
            ->addColumn(Column::tinyInteger('type')->setNull(true)->setDefault(null)->setComment('商品来源'))
            ->addColumn('audit_id', 'integer', ['limit' =>  11, 'null' => true, 'default' => null, 'comment' => '审核单ID'])
            ->addColumn('goods_id', 'integer', ['limit' =>  11, 'null' => true, 'default' => null, 'comment' => '商城商品ID'])
            ->addColumn('name', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '商品名称'])
            ->addColumn('cover_img_url', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '封面图'])
            ->addColumn(Column::tinyInteger('price_type')->setNull(true)->setDefault(null)->setComment('价格类型'))
            ->addColumn('price', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => true, 'default' => null, 'comment' => '价格'])
            ->addColumn('price2', 'decimal', ['precision' => 10, 'scale' => 2, 'null' => true, 'default' => null, 'comment' => '价格2'])
            ->addColumn(Column::tinyInteger('third_party_tag')->setNull(true)->setDefault(null)->setComment('添加商品标识'))
            ->addColumn('third_party_appid', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '第三方小程序APPID'])
            ->addColumn(Column::tinyInteger('on_shelves')->setNull(true)->setDefault(null)->setComment('上架状态'))
            ->addColumn(Column::tinyInteger('audit_status')->setNull(true)->setDefault(null)->setComment('审核状态'))
            ->addColumn('url', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '商品链接'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        // 优惠券
        $table = $this->table('shop_mplive_room');
        $table->drop();

        // 用户优惠券
        $table = $this->table('shop_mplive_goods');
        $table->drop();
    }
}
